<?php

class Smilies
{
	
	public static $smiliesF;
	
	// Smilies list
    public static $smilies = array(':yes:' => 'agree.gif', ':angel:' => 'angel.gif', ':arrow:' =>
        'arrow.gif', ':D' => 'biggrin.gif', ':bow:' => 'bow.gif', ':S' => 'confused.gif',
        ':?' => 'confused.gif', '8-)' => 'cool.gif', ':\'(' => 'cry.gif', ':cry:' =>
        'cry.gif', ':no:' => 'disagree.gif', '8|' => 'eek.gif', ':eek:' => 'eek.gif',
        ':evil:' => 'evil.gif', ':!:' => 'exclaim.gif', ':(' => 'frown.gif', ':frown:' =>
        'frown.gif', 'X(' => 'furious.gif', ':furious:' => 'furious.gif', ':heart:' =>
        'heart.gif', ':love:' => 'heart.gif', ':idea:' => 'idea.gif', ':lol:' =>
        'lol.gif', ':mad:' => 'mad.gif', '^^' => 'mrgreen.gif', ':mrgreen:' =>
        'mrgreen.gif', ':|' => 'neutral.gif', ':paper:' => 'paper.gif', ':-/' =>
        'pfffft.gif', ':drunk:' => 'pissed.gif', ':?:' => 'question.gif', ':P' =>
        'razz.gif', ':roll:' => 'rolleyes.gif', ':rolleyes:' => 'rolleyes.gif', ':sad:' =>
        'sad.gif', ':shrug:' => 'shrug.gif', ':)' => 'smile.gif', ':o' =>
        'surprised.gif', ':twisted:' => 'twisted.gif', ':]' => 'veryhappy.gif', ':bash:' =>
        'wallbash.gif', ':wallbash:' => 'wallbash.gif', ';)' => 'wink.gif', ':nod:' =>
        'yes.gif');

    // Special characters that need to replaced to be parsed properly.
    public static $smiliesR = array(')' => '\)', '(' => '\(', '/' => '\/', '|' => '\|', '^' =>
        '\^', '?' => '\?');
	
    public static function smiley_sort($a, $b)
    {
        if (strlen($a['code']) == strlen($b['code'])) {
            return 0;
        }

        return (strlen($a['code']) > strlen($b['code'])) ? -1 : 1;
    }

    public function _parse_smilies($str)
    {
        uksort(self::$smilies, 'Smilies::smiley_sort');
            foreach (self::$smilies as $code => $img) {
                $str = str_replace($code, ' <img src="' . self::$smiliesF . $img . '" alt="' . $code . '" title="' . $code .
                    '" class="smiley" /> ', $str);
            }
            
        return $str;
    }
}

Smilies::$smiliesF = System::$url . 'libs/smiley/' . $GLOBALS['setting']['smiley'] . '/';

?>